package by.semerikov.parser;

import by.semerikov.parts.Ip;
import by.semerikov.parts.Ipv4;
 

public class IpStringParser implements IStringParser<Ip>{

	@Override
	public Ip getObject(String line) {
		Ip result = null;
		String[] array = line.split("\\.");
		int num = 0;
		if(array.length == 4)
		{
			result = new Ipv4();
			num = 4;
		}
		Integer[] codes = new Integer[num];
		for(int i = 0 ; i < num ;i++)
		{
			codes[i] = Integer.parseInt(array[i]);
		}
		result.setCodes(codes);
		return result;
	}

}
